//
//  YXKindDisplayViewController.m
//  跑跑快销
//
//  Created by 杨潇 on 14-5-5.
//  Copyright (c) 2014年 ylife. All rights reserved.
//

#import "YXKindDisplayViewController.h"
#import "YXWebsiteInfoTableViewCell.h"
#import "YXPhotoListViewController.h"

@interface YXKindDisplayViewController ()

@end

@implementation YXKindDisplayViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [_searchBtn removeFromSuperview];
    if (_searchBar) {
        [_searchBar removeFromSuperview];
        [self.view endEditing:YES];
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _kindDisplayVi = [[YXKindDisplayView alloc] init];
    self.view = _kindDisplayVi;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"跑车.jpg"] forBarMetrics:UIBarMetricsDefault];
    _searchBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    _searchBtn.frame = CGRectMake(275, 10, 25, 25);
    _searchBtn.backgroundColor = [UIColor redColor];
    [_searchBtn addTarget:self action:@selector(touchSearchBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationController.navigationBar addSubview:_searchBtn];
    
    _kindDisplayVi.tabView.delegate = self;
    _kindDisplayVi.tabView.dataSource = self;
}

#pragma mark - UIButtonsClick
- (void)touchSearchBtn
{
    if (!_searchBar) {
        _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(10, 7, 300, 30)];
        _searchBar.barStyle = UIBarStyleDefault;
        _searchBar.delegate = self;
        [_searchBar setShowsCancelButton:YES];
        [self.navigationController.navigationBar addSubview:_searchBar];
    }
    _searchBar.hidden = NO;
}

#pragma mark - UISearchBarDelegate
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
    
}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [searchBar resignFirstResponder];
}

- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar
{
    searchBar.hidden = YES;
    [searchBar resignFirstResponder];
}

#pragma mark - UITableViewDataSource,UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString * identifier = @"cell";
    YXWebsiteInfoTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (nil == cell) {
        cell = [[YXWebsiteInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.nameLab.text = @"测试一下下";
    cell.addressLab.text = @"经济阿欧佛艾佛啊查看了哦IE减肥哦啊舒服i 家";
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 75;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    YXPhotoListViewController * photoListVC = [[YXPhotoListViewController alloc] init];
    photoListVC.title = @"拍照";
    [self setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:photoListVC animated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
